﻿using System;
using System.Web;
using Rabbit.Logic;
using RabbitManage.Code;

namespace RabbitManage.Action
{
    public partial class DiscountDelete : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            HttpCookie cookie = Request.Cookies[Constant.CookieName];
            string shopId = cookie.Values[Constant.CookieUid];

            string id = Request["id"];
            if (string.IsNullOrEmpty(id)) return;

            int index;
            if (!int.TryParse(id,out index))
            {
                Response.Write("false");
                return;
            }

            Shop shop = RabbitUse.GetShopByShopId(Db.Store, shopId);
            if (index <= 0 || index >= shop.Discounts.Count)
            {
                Response.Write("false");
                return;
            }
            shop.Discounts.RemoveAt(index);
            RabbitUse.AddOrUpdateShop(Db.Store, shop);

            Response.Write("true");
            Response.Redirect("~/UI/DiscountStrategy.aspx", false);
        }
    }
}